package com.scu.hotelsystem.controller;

import com.scu.hotelsystem.pojo.BaseResult;
import com.scu.hotelsystem.pojo.PageInfo;
import com.scu.hotelsystem.pojo.Vip;
import com.scu.hotelsystem.pojo.VipSearch;
import com.scu.hotelsystem.service.VipService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class VipController {
    @Autowired
    private VipService vipService;

    @RequestMapping("getVipListByPage")
    @ResponseBody
    public Map getVipListByPage(VipSearch info){
        List<Vip> vipList = vipService.getVipListByPage(info);
        int count = vipService.getVipCount(info);
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count); //总条数
        map.put("data",vipList); //当前页显示的数据
        return map;
    }

    @RequestMapping("getVipMain")
    public ModelAndView getVipMain(){
        ModelAndView view = new ModelAndView("viplist");
        return view;

    }
    //删除房客信息
    @RequestMapping("delVip")
    @ResponseBody
    public BaseResult delVip(Integer guest_id){
        int res = vipService.delVip(guest_id);
        BaseResult result = new BaseResult();
        if (res > 0){
            result.setCode(0);
        }
        else{
            result.setCode(-1);
            result.setMsg("删除失败！");
        }
        return result;
    }
    @RequestMapping("addVip")
    @ResponseBody
    public BaseResult addVip(Vip vip){
        int resp = vipService.addVip(vip);
        BaseResult result = new BaseResult();
        if (resp > 0){
            result.setCode(0);
        }
        else{
            result.setCode(-1);
            result.setMsg("添加失败！");
        }
        return result;

    }

}


